const goodsModel = require('../model/goods')

module.exports = class {
  static async list(ctx) {
    const {page, limit, title, cate} = ctx.request.body
    const data = {
      title: new RegExp(title),
      cate
    }
    !title && delete data.title
    !cate && delete data.cate
    const total = await goodsModel.find(data).countDocuments()
    const list = 
    await goodsModel.find(data)
    .skip((page-1)*limit)
    .limit(limit)
    .sort({create_time: -1})
    ctx.body = {
      err: 0,
      msg: 'success',
      data: {list, total}
    }
  }
}